package com.cmcc.aregister.cs.util;

import java.util.LinkedList;

import com.cmcc.aregister.cs.model.ActivityModel;

public class ActivityStack {

	private LinkedList<ActivityModel> ll = new LinkedList<ActivityModel>();

	// 添加
	public synchronized void push(ActivityModel o) {
		if (o != null) {
			// if (!containKey(o)) {
			ll.addFirst(o);
			// }
		}
	}

	// 删除并返回删除对象
	public synchronized ActivityModel pop() {
		if (!empty()) {
			return ll.removeFirst();
		}
		return null;
	}

	// 返回当前对象
	public synchronized ActivityModel peek() {
		if (!empty()) {
			return ll.getFirst();
		}
		return null;
	}

	// 栈是否为空
	public synchronized boolean empty() {
		// return ll.size() < 2;
		return ll.isEmpty();
	}

	public synchronized boolean containKey(ActivityModel str) {
		boolean flag = false;
		for (ActivityModel s : ll) {
			if (s.activityClass.getName().equals(str.activityClass.getName())) {
				flag = true;
				break;
			}
		}
		return flag;
	}

	public synchronized boolean remove(ActivityModel str) {
		for (ActivityModel s : ll) {
			if (s.activityClass.getName().equals(str.activityClass.getName())) {
				ll.remove(s);
				break;
			}
		}
		return true;
	}

	public synchronized int size() {
		return ll.size();
	}

	// 清空栈
	public synchronized void clear() {
		ll.clear();
	}
}
